package com.liangdemo.web.thread;

import java.io.IOException;

/**
 * 模拟多线程出错回滚
 *
 * @Name LiangErLe
 * @date 2022/6/9 15:43
 */
public class ThreadDemo4 {
    public static void main(String[] args) throws IOException {
        Thread t1 = new MyTask("线程1", 3, true);
        Thread t2 = new MyTask("线程2", 4, true);
        Thread t3 = new MyTask("线程3", 1, false);
        t1.start();
        t2.start();
        t3.start();
        System.in.read();
    }

    static class MyTask extends Thread {
        private String name;
        private int timeInSeconds;
        private boolean success;

        public MyTask(String name, int timeInSeconds, boolean success) {
            this.name = name;
            this.timeInSeconds = timeInSeconds;
            this.success = success;

        }

        public void run() {
            try {
                Thread.sleep(timeInSeconds * 1000);
                System.out.println(name + "  任务结束");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

        }
    }

}
